package asteroids.model.expressions;

import exceptions.IllegalOperandException;

/**
 * A subclass of expression (E) that represents the siinus operantion (sin x) of a doubles
 * 
 * @version 1.0
 * 
 * @author	Thijs Peirelinck & Wouter Parys
 *
 */
public class Sin extends MathExpression {
	
	public Sin(E e) {
		super(e);
	}
	
	@Override
	public boolean isValidExpression() {
		return (getOperand().getReturnType().equals("double") && !(getOperand() == this));
	}

	@Override
	public Double getValue() {
		if(!this.isValidExpression()) { throw new IllegalOperandException(); }
		return Math.sin(((Double)getOperand().getValue()));
	}
	
	@Override
	public String toString() {
		return "sin(" + getOperand().toString() + ")";
	}
	
	@Override
	public E createCopy() {
		return new Sin(getOperand().createCopy());
	}
}
